using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;

namespace TrainingManagement.api.Models.Data.CRUD.TrainingRecord
{
    public class TrainingRecordUpdateDataSource : NonQuerySource<BusinessObjects.TrainingRecord>
    {
        public override bool Execute(BusinessObjects.TrainingRecord request)
        {
            const string updateTrainingRecord = "dbo.training_api_TrainingRecordUpdate";
            var parameters = new SqlParameter[5];
            parameters[0] = new SqlParameter("@TrainingRecordID", SqlDbType.Int){Value = request.TrainingRecordId};
            parameters[1] = new SqlParameter("@EmployeeID", SqlDbType.Int){Value = request.EmployeeId};
            parameters[2] = new SqlParameter("@DueDate", SqlDbType.DateTime){Value = request.DueDate};
            parameters[3] = new SqlParameter("@CompletedDate", SqlDbType.DateTime){Value = request.CompletedDate};
            parameters[4] = new SqlParameter("@SkillID", SqlDbType.Int){ Value = request.SkillId};

            return SqlHelper.ExecuteNonQuery(
                ConnectionStrings.TrainingDb,
                CommandType.StoredProcedure,
                updateTrainingRecord,
                parameters) != 0;
        }
    }
}